/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.exception.CaptchaException;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class JiangxiSearchEngine extends SearchEngine
/*     */ {
/*  20 */   private static Logger logger = Logger.getLogger(JiangxiSearchEngine.class
/*  21 */     .getName());
/*     */ 
/*  23 */   private Map<String, String> params = new HashMap();
/*     */ 
/*     */   public JiangxiSearchEngine(String name) {
/*  26 */     this.name = standardizedName(name);
/*  27 */     this.params.put("注册号：", "SN");
/*  28 */     this.params.put("企业类型：", "CompanyType");
/*  29 */     this.params.put("企业名称：", "CompanyName");
/*  30 */     this.params.put("法定代表人（负责人）：", "Header");
/*  31 */     this.params.put("成立日期：", "FoundedDate");
/*  32 */     this.params.put("注册资本（资金数额）：", "RegisteredCapital");
/*  33 */     this.params.put("经营期限起：", "OperatingPeriodStart");
/*  34 */     this.params.put("经营期限止：", "OperatingPeriodEnd");
/*  35 */     this.params.put("登记机关：", "RegistrationAuthority");
/*  36 */     this.params.put("住所：", "Address");
/*  37 */     this.params.put("经营范围：", "BusinessScope");
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */     throws CaptchaException
/*     */   {
/*  46 */     JiangxiSearchEngine searchEngine = new JiangxiSearchEngine(
/*  47 */       "景德镇市腾锦贸易有限公司");
/*     */ 
/*  49 */     Map items = searchEngine.getCompanyByWeb();
/*  50 */     System.out.println(items);
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */     throws CaptchaException
/*     */   {
/*  56 */     if (!isValid(this.name)) {
/*  57 */       return null;
/*     */     }
/*  59 */     String url = null;
/*     */     try {
/*  61 */       url = "http://218.65.88.119:8899/getEnterprisesByCodition.action?item_code=&lawperson=&companyname=" + URLEncoder.encode(this.name.trim(), "utf-8");
/*     */     } catch (UnsupportedEncodingException e) {
/*  63 */       url = "http://218.65.88.119:8899/getEnterprisesByCodition.action?item_code=&lawperson=&companyname=" + this.name.trim();
/*     */     }
/*     */     try {
/*  66 */       Document doc = Jsoup.connect(url).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/*  67 */         .timeout(10000).get();
/*  68 */       Elements links = doc.select("table[id=mytable] tr[height=22] td a");
/*  69 */       String detailUrl = null;
/*  70 */       if ((links != null) && (links.size() >= 1)) {
/*  71 */         detailUrl = links.get(0).absUrl("href");
/*     */       }
/*     */ 
/*  74 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0)) {
/*  75 */         return null;
/*     */       }
/*     */ 
/*  79 */       doc = Jsoup.connect(detailUrl).userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)").timeout(10000)
/*  80 */         .get();
/*  81 */       links = doc.select("table th");
/*  82 */       if (links == null) {
/*  83 */         return null;
/*     */       }
/*     */ 
/*  86 */       Map info = new HashMap();
/*     */ 
/*  88 */       for (Element item : links) {
/*  89 */         String key = item.text().trim();
/*  90 */         if (this.params.containsKey(key))
/*     */         {
/*  93 */           info.put((String)this.params.get(key), item.nextElementSibling().text());
/*     */         }
/*     */       }
/*  96 */       info.put("OperatingPeriod", info.get("OperatingPeriodStart") + " - " + 
/*  97 */         info.get("OperatingPeriodEnd"));
/*  98 */       info.put("UpdateDate", Util.date2Str(new Date()));
/*  99 */       if (info.size() > 1)
/*     */       {
/* 101 */         saveDB(info);
/*     */       }
/*     */ 
/* 104 */       return info;
/*     */     } catch (IOException e) {
/* 106 */       logger.warn("get company from web failed", e);
/*     */     }
/*     */ 
/* 109 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.JiangxiSearchEngine
 * JD-Core Version:    0.6.1
 */